package com.iflytek.day28._01_serialize;

import java.io.*;

public class _03_ObjectStreamDemo {
  public static void main(String[] args) throws IOException, ClassNotFoundException {
    // write();
    read();
  }

  // 反序列化
  private static void read() throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src\\com\\iflytek\\day28\\_01_serialize\\oos.txt"));
    Object obj = ois.readObject();
    Student s = (Student) obj;
    System.out.println(s.getName() + "," + s.getAge());
    ois.close();
  }

  // 序列化
  private static void write() throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\com\\iflytek\\day28\\_01_serialize\\oos.txt"));
    Student s = new Student("佟丽娅", 30);
    oos.writeObject(s);
    oos.close();
  }
}
